home *** CD-ROM | disk | FTP | other *** search
/ Loadstar - Compleat Programmer / comprog1.d81 / b.faster basic (.txt) < prev    next >
Commodore BASIC  |  2022-08-28  |  3KB  |  79 lines

  1. 10 dim w$(50):print"[147]":menu=12:poke53272,21
  2. 20 a$="loading words.  please wait...":gosub430
  3. 30 poke214,16:print:print"[152]"spc(20-len(a$)/2)a$
  4. 40 open2,8,2,"words":fori=1to50:input#2,w$(i):next:close2
  5. 50 poke198,0:restore:gosub430:fory=1to11:reada$:gosub400:next
  6. 60 geta$:ifa$<"1"ora$>"5"then60
  7. 70 onval(a$)gosub110,150,260,80,740:goto50
  8. 80 print"[147]"
  9. 90 fori=1to50:printw$(i),:wait197,64:next
  10. 100 print:print"any key to continue ":poke198,0:wait198,1:print"[147]":return
  11. 110 rem============shuffle===========
  12. 120 a$="shuffling":gosub430:poke214,16:print:print"[152]"spc(20-len(a$)/2)a$
  13. 130 forj=1to50:j%=rnd(ti)*50+1
  14. 140 t$=w$(j):w$(j)=w$(j%):w$(j%)=t$:next:return
  15. 150 rem========bubble sort=======
  16. 160 a$="bubble sorting":gosub430:poke214,16:print:print"[152]"spc(20-len(a$)/2)a$
  17. 170 c=0:ti$="000000":forp=1to51:fors=1to49
  18. 180 ifw$(s)>w$(s+1)thenc=c+1:a$=w$(s):w$(s)=w$(s+1):w$(s+1)=a$
  19. 190 next:poke53280,p:next
  20. 200 rem =========bubble sort end=====
  21. 210 tb$=ti$:gosub430:y=13:a$="time:"+str$(val(tb$)):gosub380
  22. 220 a$=str$(c)+" total switches"
  23. 230 gosub380:a$="press a key...":gosub380:poke198,0:wait198,1:poke198,0
  24. 240 restore:fori=1to12:read a$:next:y=11:fori=1to11:reada$:gosub380:next
  25. 250 poke198,0:wait198,1:return
  26. 260 rem=====quick sort=======
  27. 270 a$="quick sorting":gosub430:poke214,16:print:print"[152]"spc(20-len(a$)/2)a$
  28. 280 c=0:ti$="000000":b=1:q=50:forp=1to50/2:a$="":b$="zz":fors=bto50-p:c$=w$(s)
  29. 290 ifc$>a$thenifc$>w$(q)thenc=c+1:a$=w$(q):w$(q)=c$:w$(s)=a$:goto310
  30. 300 ifc$<b$thenifc$<w$(b)thenc=c+1:b$=w$(b):w$(b)=c$:w$(s)=b$
  31. 310 next:q=q-1:b=b+1:poke53280,p:next
  32. 320 rem=======end quick sort========
  33. 330 tp$=ti$:gosub430:y=13:a$="time:"+str$(val(ti$)):gosub380
  34. 340 a$=str$(c)+" total switches"
  35. 350 gosub380:a$="press a key...":gosub380:poke198,0:wait198,1:poke198,0
  36. 360 restore:fori=1to23:read a$:next:y=11:fori=1to11:reada$:gosub380:next
  37. 370 poke198,0:wait198,1:return
  38. 380 poke214,y:print:print"[152]"a$:y=y+1:return
  39. 390 stop
  40. 400 rem main print
  41. 410 poke214,10+y:print:print"[152]"a$"":return
  42. 420 stop
  43. 430 poke53280,0:poke53281,0
  44. 440 print"[146]        [159]**** faster sorting ****"
  45. 450 print" [155][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][184][152]"
  46. 460 fori=1to11:print"                                      ":next
  47. 470 print" [151][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185][185]";
  48. 480 print"[159]";:return
  49. 490 data,this program will sort 50 words
  50. 500 data using the old bubble sort code and
  51. 510 data a version of the quick sort.,
  52. 520 data,1. to shuffle words,2. bubble sort
  53. 530 data3. quick sort,4. view words
  54. 540 data5. quit
  55. 550 data,the bubble sort will switch item
  56. 560 data1 with 2 if 1 is of greater value.
  57. 570 dataif item 2 > item 3 then they are
  58. 580 dataswitched next.  this goes on for
  59. 590 data"51 passes.         "
  60. 600 data100 items need 101 passes.
  61. 610 datathis isn't very efficient since
  62. 620 datathe sort may have to move the same
  63. 630 data same item more than once.,,press a key...
  64. 640 datathe quick sort finds the two most
  65. 650 data extreme values and places them.
  66. 660 data after this it does less work because
  67. 670 data it shaves its limits of concern.
  68. 680 datathe top and bottom ranges are closed
  69. 690 data in.  the list is sorted from the,outside in.,
  70. 700 you can increase the speed of this sort!
  71. 710 data basic can get the job done faster
  72. 720 dataif it juggles fewer bytes and,reads fewer instructions! (return)
  73. 730 printpeek(197):goto730
  74. 740 open15,8,15,"r0:hello connect=hello connect":input#15,er:close15
  75. 750 if er<>63 then print"[147]":end
  76. 760 a$="hello connect":q$=chr$(34)
  77. 770 print"[144][147]load"q$a$q$",8"
  78. 780 print"run":poke631,13:poke632,13:poke198,2:end
  79.